<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Base Business class, implements comment methods for all child businesses
 * @author dangld
 *
 */
class Business extends CI_Base
{
	var $_parent_name = '';
	var $CI = null;
	var $db_payment = null;
    var $errormessage="";
		
	function __construct(){
		$this->CI =& get_instance();
		
		$this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
		$this->_parent_name = ucfirst(get_class($this));
		
		$this->getDbPayment();
	}
	
	function getDbPayment(){
		if(is_object($this->db_payment)){
			return false;
		}
		$this->db_payment = $this->CI->load->database(DB_PAYMENT, true);
	}
	
	/**
	 * Assign Libraries
	 *
	 * Creates local references to all currently instantiated objects
	 * so that any syntax that can be legally used in a controller
	 * can be used within models.  
	 *
	 * @access private
	 */	
	function _assign_libraries($use_reference = TRUE)
	{
		$CI =& get_instance();				
		foreach (array_keys(get_object_vars($CI)) as $key)
		{
			if ( ! isset($this->$key) AND $key != $this->_parent_name)
			{			
				// In some cases using references can cause
				// problems so we'll conditionally use them
				if ($use_reference == TRUE)
				{
					$this->$key = NULL; // Needed to prevent reference errors with some configurations
					$this->$key =& $CI->$key;
				}
				else
				{
					$this->$key = $CI->$key;
				}
			}
		}		
	}
}